<?php


include 'C:\Users\huwang\Desktop\大商户代子商户发起提现\Method summary.php';
use function Method\RSA2sign;
use function Method\PostJson;
use function Method\RSA2data;
use function Method\rsaDecrypt;

//定义参数值
$version = '1.0';//版本号
$agent_id = '';//大商户号7位数ID
$out_trade_no = '';//商户订单号
$sub_account_id = '';//子商户号7位数ID
$cash_fen = '1';//提现金额
$note = '';//提现备注
$notify_url = 'https://demo.heemoney.com';//异步通知地址，必须以https://或http://开头完整的URL地址

//签名前数据
$Beforesign = array(
    "version" => $version,
    "agent_id" => $agent_id,
    "out_trade_no" => $out_trade_no,
    "sub_account_id" => $sub_account_id,
    "cash_fen" => $cash_fen,
    "note" => $note,
    "notify_url" => $notify_url,
);
$signatureContent = json_encode($Beforesign,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);//组装签名串
echo "签名串:" .$signatureContent;//输出签名前参数
echo "<br/><hr>";
$Aftersign= RSA2sign($signatureContent);//签名结果
echo "签名结果:" .$Aftersign;//输出签名结果
echo "<br/><hr>";


//加密
$data = array(
    "sign" => $Aftersign,//私钥签名结果
    "body" => $signatureContent,
);



$Befordata = json_encode($data);//组装加密前数据
echo "待加密数据:" .$Befordata;
echo "<br/><hr>";
$Afterdata = RSA2data($Befordata);
echo "加密结果:" .$Afterdata;//加密结果
echo "<br/><hr>";

/*
公共请求参数
*/
//$agentid= $agent_id;
//$businessContext= $Afterdata;


// 构建请求的JSON数据
$request_data = array(
    "agentid" => $agent_id,
    "businessContext" => $Afterdata,
);


// 将数组转换为JSON字符串
$jsonString = json_encode($request_data,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);


//输出请求数据
echo "请求json".$jsonString;
echo "<br/><hr>";


$Posturl = "https://www.heepay.com/API/Agent/AgentSubCash.aspx";
$jsonData = $jsonString;


$Responsedata = PostJson($Posturl,$jsonData);//获取响应参数
$beforedecryption = json_decode($Responsedata, true);
echo $beforedecryption["businessContext"];//获取需要解密的数据

//解密
$Decrypteddata = rsaDecrypt(base64_decode($beforedecryption["businessContext"]));

echo $Decrypteddata ;//解密结果





?>